#ifndef E_ITEM_H
#define E_ITEM_H

#include <DefineLibCommon.h>
#include <DefineCommon.h>
#include <memory>
#include <EItemMeta.h>

/**The base class that stores all useful information for ui.
 * All other extended functions should inherit this class and build a wrap class type.
 * */
struct EItemData;
class EItem;
typedef SmartPtr(EItem) EItemPtr;
typedef std::vector<EItemPtr> EItemList;
typedef EItemMetaPtr (*Fun_createMeta)(EItem*);
class COMMON_DLL EItem 
{
public:
    EItem();
    virtual ~EItem();

    void setName(const char* strName);
    EString getName();

    EString getType();

    /*A int tag value for item manager in outside program. This value is just the conversion of this pointer to int*/
    long getTag();

    void setDescription(const char* strName);
    EString getDescription();

    /****Adding releated functions******/
    /**add child to this*/
    virtual void addChild(EItemPtr childItem);
    /** Insert child at specific location.
     * The new child is inserted into the child list
     * before the node at the specified index.
     */
    virtual bool insertChild(int index, EItemPtr child );

    /****Finding releated functions******/
    /**get child item from this*/
    virtual EItemPtr getChild(int index);
    /**get child item index by ptr, return -1 if not found*/
    virtual int getChildIndex(EItem* childPtr);
    /**get parent item index by ptr, return -1 if not found*/
    virtual int getParentIndex(EItem* parentPtr);
    /**get children count*/
    size_t getChildCount();
    /** Return true if child is contained within. */
    bool containsChild( const EItemPtr child );

    /****removing releated functions******/
    /**remove a child by index*/
    virtual bool removeChild(int index, int numChildrenToRemove=1);
    /**remove a child by index*/
    virtual bool removeParent(int index, int numParentToRemove=1);
    /**remove a child by ptr*/
    virtual bool removeChild(EItem* childPtr);
    /**remove a parent by ptr*/
    virtual bool removeParent(EItem* parentPtr);

    /****Changing releated functions******/
    // virtual bool changeParent(EItem* parentNew, EItem* parentOld);
    // virtual void selectThis();


    virtual EItemMetaPtr getOrCreatMeta();

    //called by autogen.h
    void setFunCreateMeta(Fun_createMeta fun);

    EString getPrintStr();
protected:
    //private data that includes child item list and property list
    EItemData* m_data;

    //
    EString m_name;
    //type of this class, notice that type can not be set by outer
    EString m_type;
    //The description of this class
    EString m_description;

};

#endif // EITEM_H
